package xpn.platform.common.persistence;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;

@MappedSuperclass
public abstract class AbstractEntity implements Entity<Long>, Serializable {

	private static final long serialVersionUID = -593848789986709920L;

	@Id
	@GeneratedValue(generator = "commonsequence")
	@GenericGenerator(name = "commonsequence", strategy = "native")   
	private Long id;
	@Override
	public Long getId() {
		return id;
	}
	@Override
	public void setId(Long id) {
		this.id = id;
	}

	@Override
	@JsonIgnore
	public boolean isNew() {
		if (this.id == null) {
			this.setId(null);
			return true;
		}
		return false;
	}

	/**
	 * 转换老数据使用的字段 by zk
	 */
    @Column(unique = true)
	private String oldId;

	public String getOldId() {
		return oldId;
	}

	public void setOldId(String oldId) {
		this.oldId = oldId;
	}
}
